from rest_framework.viewsets import ModelViewSet
from rest_framework import generics
from goods.models import SPUSpecification
from meiduo_admin.utils.pagination import MeiduoPagination
from meiduo_admin.serializers.specs import SpecsSerializer, SpecBySpuSerializer


class SpecsModelViewSet(ModelViewSet):
    queryset = SPUSpecification.objects.all()
    serializer_class = SpecsSerializer
    pagination_class = MeiduoPagination


class SpecBySpuView(generics.ListAPIView):
    def get_queryset(self):
        spu_id = self.kwargs.get('pk')  ## self的三个属性
        queryset = SPUSpecification.objects.filter(spu_id=spu_id)
        return queryset

    serializer_class = SpecBySpuSerializer
